package com.cjq.domain;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * (User)实体类
 *
 * @author makejava
 * @since 2021-06-12 00:15:37
 */
@Data
@Accessors(chain = true)
public class User implements UserDetails, Serializable {

    @TableId(value = "id",type = IdType.AUTO)
    @ExcelIgnore
    private Integer id;
    /**
     * 用户名（学号）
     */
    @ExcelProperty("学号")
    private String username;
    /**
     * 登录密码
     */
    @ExcelIgnore
    private String password;
    /**
     * 密码登录 false表示通过第三方登录
     */
    @ExcelIgnore
    private Object enablePassword;
    /**
     * 教工还是学生,1表示学生,0表示教工
     */
    @ExcelProperty("用户类型")
    private Integer userType;
    /**
     * 角色id
     */
    @ExcelIgnore
    private Integer roleId;
    /**
     * 真实姓名
     */
    @ExcelProperty("姓名")
    private String realName;
    /**
     * 联系号码
     */
    @ExcelProperty("联系号码")
    private String phone;
    /**
     * 学校
     */
    @ExcelProperty("学校")
    private String school;
    /**
     * 院系
     */
    @ExcelProperty("院系")
    private String department;
    /**
     * 年级
     */
    @ExcelProperty("年级")
    private Integer grade;
    /**
     * 专业
     */
    @ExcelProperty("专业")
    private String major;
    /**
     * 班级
     */
    @ExcelProperty("班级")
    private String className;

    @TableField(exist = false)
    @ExcelIgnore
    List<GrantedAuthority> authorities; //用户权限集合

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

    private static final long serialVersionUID = 1L;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        com.cjq.domain.User other = (com.cjq.domain.User) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
                && (this.getUsername() == null ? other.getUsername() == null : this.getUsername().equals(other.getUsername()))
                && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()))
                && (this.getEnablePassword() == null ? other.getEnablePassword() == null : this.getEnablePassword().equals(other.getEnablePassword()))
                && (this.getUserType() == null ? other.getUserType() == null : this.getUserType().equals(other.getUserType()))
                && (this.getRoleId() == null ? other.getRoleId() == null : this.getRoleId().equals(other.getRoleId()))
                && (this.getRealName() == null ? other.getRealName() == null : this.getRealName().equals(other.getRealName()))
                && (this.getPhone() == null ? other.getPhone() == null : this.getPhone().equals(other.getPhone()))
                && (this.getSchool() == null ? other.getSchool() == null : this.getSchool().equals(other.getSchool()))
                && (this.getDepartment() == null ? other.getDepartment() == null : this.getDepartment().equals(other.getDepartment()))
                && (this.getGrade() == null ? other.getGrade() == null : this.getGrade().equals(other.getGrade()))
                && (this.getMajor() == null ? other.getMajor() == null : this.getMajor().equals(other.getMajor()))
                && (this.getClassName() == null ? other.getClassName() == null : this.getClassName().equals(other.getClassName()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getUsername() == null) ? 0 : getUsername().hashCode());
        result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
        result = prime * result + ((getEnablePassword() == null) ? 0 : getEnablePassword().hashCode());
        result = prime * result + ((getUserType() == null) ? 0 : getUserType().hashCode());
        result = prime * result + ((getRoleId() == null) ? 0 : getRoleId().hashCode());
        result = prime * result + ((getRealName() == null) ? 0 : getRealName().hashCode());
        result = prime * result + ((getPhone() == null) ? 0 : getPhone().hashCode());
        result = prime * result + ((getSchool() == null) ? 0 : getSchool().hashCode());
        result = prime * result + ((getDepartment() == null) ? 0 : getDepartment().hashCode());
        result = prime * result + ((getGrade() == null) ? 0 : getGrade().hashCode());
        result = prime * result + ((getMajor() == null) ? 0 : getMajor().hashCode());
        result = prime * result + ((getClassName() == null) ? 0 : getClassName().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", username=").append(username);
        sb.append(", password=").append(password);
        sb.append(", enablePassword=").append(enablePassword);
        sb.append(", userType=").append(userType);
        sb.append(", roleId=").append(roleId);
        sb.append(", realName=").append(realName);
        sb.append(", phone=").append(phone);
        sb.append(", school=").append(school);
        sb.append(", department=").append(department);
        sb.append(", grade=").append(grade);
        sb.append(", major=").append(major);
        sb.append(", className=").append(className);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }

}